//
//  AppDelegate.m
//  Objective-C
//
//  Created by S_Line on 2018/5/3.
//  Copyright © 2018年 S_Line. All rights reserved.
//

#import "AppDelegate.h"

#import "SLRootViewController.h"
#import "SLNavigationController.h"
#import "SLDebuger.h"

#import <JLRoutes/JLRoutes.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [self launchInit];
    
    [self initWindow];
    
    return YES;
}

- (void)launchInit {
//    kScreenWidth = [UIScreen mainScreen].bounds.size.width;
//    kScreenHeight = [UIScreen mainScreen].bounds.size.height;
    if (kScreenHeight == 812) {
        kStatusBarHeight = 44;
        kNavigationBarHeight = 88;
        kSafeBottomMargin = 34;
        IS_IPHONE_X = true;
    } else {
        kStatusBarHeight = 20;
        kNavigationBarHeight = 64;
        kSafeBottomMargin = 0;
        IS_IPHONE_X = false;
    }
    
    kOnePixelWidth = 1.0 / [UIScreen mainScreen].scale;
    kOnePixelAdjustOffset = kOnePixelWidth / 2.0;
}

- (void)initWindow {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
    SLRootViewController *vc = [[SLRootViewController alloc] initWithNibName:@"SLRootViewController" bundle:nil];
    SLNavigationController *nav = [[SLNavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nav;
    
    [SLVDNSManager shareInstance].navigationController = nav;
    [self.window makeKeyAndVisible];
    
    [[SLDebuger sharedInstance] showDebuger];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    NSLog(@"applicationWillResignActive");
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
    NSLog(@"applicationDidEnterBackground");
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    NSLog(@"applicationWillEnterForeground");
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    
    NSLog(@"applicationDidBecomeActive");
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


/**
 <#Description#>

 @param app <#app description#>
 @param url <#url description#>
 @param options <#options description#>
 @return <#return value description#>
 
 url: sloc://onevc?id=2&number=5
 host: onevc
 scheme: sloc
 query: id=2&number=5
 
 UIApplicationOpenURLOptionsKey的可选值
    - UIApplicationOpenURLOptionsSourceApplicationKey
    - UIApplicationOpenURLOptionsAnnotationKey
    - UIApplicationOpenURLOptionsOpenInPlaceKey
 */
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
    
    NSLog(@"0");
    NSLog(@"url.absoluteString: %@", url.absoluteString);
    NSLog(@"url.scheme: %@", url.scheme);
    NSLog(@"url.host: %@", url.host);
    NSLog(@"url.query: %@", url.query);
    NSLog(@"options: %@", options);
    
    return true;
}


/**
 已经被废弃
 */
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    NSLog(@"1");
    NSLog(@"从哪个app跳转而来 Bundle ID: %@", sourceApplication);
    NSLog(@"URLScheme: %@", url.scheme);
    
    return true;
}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
    if (![UIDevice currentDevice].isPad) {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    if (self.allowRotation == YES) {
        //横屏
        return UIInterfaceOrientationMaskAll;
        
    }else{
        //竖屏
        return UIInterfaceOrientationMaskPortrait;
        
    }
    
}




@end
